#include <stdio.h>

int count_i(const char *filename)
{
    FILE *file = fopen(filename, "r");
    if (file == NULL)
    {
        printf("无法打开文件： %s\n", filename);
        return -1;
    }

    int i = 0;
    char ch;
    while ((ch = fgetc(file)) != EOF)
    {
        if (ch == '\n')
        {
            i++;
        }
    }

    fclose(file);
    return i;
}

int main()
{
    const char *filename = "hqyj.txt";
    int line_count = count_i(filename);
    if (line_count >= 0)
    {
        printf("文件 %s 有 %d 行数据。\n", filename, line_count);
    }
    return 0;
}
